﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DatabasesAddValue.aspx.cs" MasterPageFile="~/Site.master" Inherits="DatabasesAddValue" %>

<asp:Content ID="Content1" ClientIDMode="Static" runat="server" ContentPlaceHolderID="BodyContent">
    <div class="contentfull">
        <div class="breadcrumbs">
            <ul id="crumbs">
                <li><a title="My Account" href="#">My Account</a>
                    <img src="Content/Images/separator.png" alt="&rarr;" class="separator">
                    Rosters 			</li>
            </ul>
        </div>

        <div id="showMessages">
            <%= GetMessage() %>
        </div>
        <div class="top">
            <div class="innerleft">
                <h1>
                    <img src="Images/database-icon.png" width="32px" height="32px" alt="Database">
                    <span id="databaseName"><% =GetDatabaseName() %></span>
                    <form id="renameform">
                        <input type="hidden" name="action" value="renamedb" />
                        <input type="hidden" id="hdnUserId" name="hdnUserId" value="<% =GetUserId() %>" />
                        <input type="hidden" name="listid" id="listid" value="<% =GetDatabaseId() %>" />
                        <input type="text" class="inputed" id="dbname" name="dbname" value="<% =GetDatabaseName() %>" />
                        <input type="submit" id="rename-button" value="Rename" />
                    </form>
                    <a id="rename1" title="Click to rename">Rename</a>
                </h1>
                <span class="db_value"><% =GetCaseSensitiveCount() %></span>
                <script type="text/javascript">
                    $(document).ready(function () {
                        var messengerDiv = $("div#showMessages");
                        $("#rename1").click(function (event) {
                            $('#databaseName').hide();
                            $("#rename1").hide();
                            $("#renameform").show().css("display", "inline");
                            return false;
                        });

                        $("#dbname").click(function (event) {
                            return false;
                        });

                        $("#renameform").submit(function (event) {
                            var _data = '<?xml version="1.0" encoding="utf-8"?>' +
                                            '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
                                            '<soap:Body>' +
                                                '<RenameDatabase xmlns="http://tempuri.org/">' +
                                                    ' <dbId>' + $("input#listid").val() + '</dbId>' +
                                                    '<newDBName>' + $("input#dbname").val() + '</newDBName>' +
                                                    ' <loggedInUserId>' + $("input#hdnUserId").val() + '</loggedInUserId>' +
                                                    '</RenameDatabase>' +
                                                '</soap:Body>' +
                                           '</soap:Envelope>';
                            // alert(_data);
                            $.ajax({
                                type: "POST",
                                url: "http://ssica.org/services/CommonService.asmx?op=RenameDatabase",
                                data: _data,
                                contentType: "text/xml;charset-uf8",
                                dataType: "xml",
                                success: function (msg) {
                                    var result = $("RenameDatabaseResult", msg);
                                    var res = $(result).text();
                                    // alert(res);
                                    if (res != 'error') {
                                        $("#renameform").hide();
                                        $("#databaseName").fadeIn().html(res);
                                        $("#dbname").val(res);
                                        messengerDiv.removeClass().addClass("success");
                                        var showMessage = 'Roster has been renamed.';
                                        if (messengerDiv.is(":empty")) {
                                            messengerDiv.empty().append("<p></p>").append("<li>" + showMessage + "</li>").hide().slideDown();
                                        } else {
                                            messengerDiv.hide().empty().append("<p></p>").append("<li>" + showMessage + "</li>").fadeIn();
                                        }
                                    } else {
                                        messengerDiv.removeClass().addClass("warning");
                                        var showMessage = 'Roster could not be renamed. Certain special characters are not allowed.';
                                        if (messengerDiv.is(":empty")) {
                                            messengerDiv.empty().append("<p></p>").append("<li>" + showMessage + "</li>").hide().slideDown();
                                        } else {
                                            messengerDiv.hide().empty().append("<p></p>").append("<li>" + showMessage + "</li>").fadeIn();
                                        }
                                    }

                                }
                            });
                            return false;
                        });

                        $("body").not("#renameform").click(function (event) {
                            if ($("#renameform").is(':visible')) {
                                $("#renameform").fadeOut();
                                $("#databaseName").delay(400).fadeIn();
                                $("#rename1").delay(400).fadeIn();
                            }
                        });

                    });

                    function ShowFileMessage(args) {
                        var messengerDiv = $("div#showMessages");
                        messengerDiv.removeClass().addClass("success");
                        // var showMessage = 'Database has been renamed.';
                        if (messengerDiv.is(":empty")) {
                            messengerDiv.empty().append("<p></p>").append("<li>" + args + "</li>").hide().slideDown();
                        } else {
                            messengerDiv.hide().empty().append("<p></p>").append("<li>" + args + "</li>").fadeIn();
                        }

                    }
                </script>
            </div>
        </div>
        <div class="content">
            <div class="tabs_box">
                <ul id="tabs">
                    <li><a class="tabs_off" href="DatabaseSearch.aspx?dbid=<% =GetDatabaseId() %>&mode=Edit">Search</a></li>
                    <li><a class="tabs_on" href="#">Add</a></li>
                    <li><a class="tabs_off" href="DatabasesImport.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Import</a></li>
                    <li><a class="tabs_off" href="DatabasesExport.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Export</a></li>
                    <%--  <li><a class="tabs_off" href="DatabasesAutofill.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Autofill</a></li>--%>
                    <li><a class="tabs_off" href="DatabasesClear.aspx?dbid=<% =GetDatabaseId() %>&mode=edit">Clear</a></li>

                </ul>
            </div>
            <div>
                <fieldset style="clear: both;">
                    <legend></legend>

                    <h2>Add a Barcode Value</h2>

                    <form method="post" id="addValues">
                        <input type="hidden" name="action" value="addvalue" />
                        <input type="hidden" name="adduserid" id="adduserid" value="<% =this.GetUserId() %>" />
                        <input type="hidden" name="listid" id="addlistid" value="<% =GetDatabaseId() %>" />
                        <div class="value">
                            <label for="barcodevalue">Student Id Number</label>
                            <input type="text" class="largeinput" id="barcodevalue" maxlength="100" name="studentIdNumber" autocomplete="off" />
                            <label for="firstName">First Name</label>
                            <input type="text" class="largeinput" id="firstName" maxlength="100" name="firstName" autocomplete="off" />
                            <label for="lastName">Last Name</label>
                            <input type="text" class="largeinput" id="lastName" maxlength="100" name="lastName" autocomplete="off" />
                            <label for="lastName">Grade</label>
                            <input type="text" class="largeinput" id="grade" maxlength="100" name="grade" autocomplete="off" />
                            <label>Validity</label>
                            <div class="radioset left full">
                                <input type="radio" name="validity" id="invalidBarcode" value="1" class="edit_invalid" checked />
                                <label for="invalidBarcode">
                                    <img src="Images/red_small.jpg" />&nbsp;&nbsp;Force an Invalid Response</label>
                                <br />
                                <input type="radio" name="validity" id="validBarcode" value="2" class="edit_invalid" />
                                <label for="validBarcode">
                                    <img src="Images/green_small.jpg" />&nbsp;&nbsp;Valid</label>
                                <br />
                                <input type="radio" name="validity" id="lunchBarcode" value="3" class="edit_invalid" />
                                <label for="lunchBarcode">
                                    <img src="Images/brown_small.jpg" />&nbsp;&nbsp;Lunch Detention</label>
                                <br />
                                <input type="radio" name="validity" id="saturdayBarcode" value="4" class="edit_invalid" />
                                <label for="saturdayBarcode">
                                    <img src="Images/yellow_small.jpg" />&nbsp;&nbsp;Saturday School</label>
                            </div>
                        </div>
                        <div class="response">
                            <label for="note1">Note 1</label>
                            <textarea name="note1" id="note1" rows="10" cols="5" class="full" placeholder="Optional. Appears with scan results."></textarea>
                            <label for="not2">Note 2</label>
                            <textarea name="note2" id="note2" rows="10" cols="5" class="full" placeholder="Optional. Appears with scan results."></textarea>
                            <label for="note3">Note 3</label>
                            <textarea name="note3" id="note3" rows="10" cols="5" class="full" placeholder="Optional. Appears with scan results."></textarea>
                            <label for="note4">Note 4</label>
                            <textarea name="note4" id="note4" rows="10" cols="5" class="full" placeholder="Optional. Appears with scan results."></textarea>
                            <p>&nbsp;</p>
                            <input type="submit" value="Add" class="black_button blarge right" />
                            <div id="LoadingDiv">
                                <img src="Images/ajax-loader.gif" />
                            </div>
                        </div>
                    </form>

                </fieldset>
            </div>
            <span id="editBarcodeFormHidden">
                <form class="editBarcodeForm">
                    <input type="hidden" name="dbid" id="dbid" value="<% =this.GetDatabaseId() %>" />
                    <input type="hidden" name="userid" id="userid" value="<% =this.GetUserId() %>" />
                    <input type="hidden" name="action" value="editvalue" />
                    <input type="hidden" name="value" id="value" />
                    Student Id#:
                    <input type="text" name="sid" class="largeinput" style="width: 100px" />
                    &nbsp;&nbsp;First Name :
                    <input type="text" name="fName" class="largeinput" style="width: 200px" />
                    &nbsp;&nbsp;Last Name :
                    <input type="text" name="lName" class="largeinput" style="width: 200px" />
                    &nbsp;&nbsp; Grade :
                    <input type="text" name="grade" class="largeinput" style="width: 75px" /><br />
                    <br />
                    Validity :
                    <input type="radio" name="validity" id="invalidBarcode1" value="1" class="edit_invalid" />
                    <label for="invalidBarcode">
                        <img src="Images/red_small.jpg" />&nbsp;&nbsp;Force an Invalid Response</label>
                    &nbsp;&nbsp;&nbsp;<input type="radio" name="validity" id="validBarcode1" value="2" class="edit_invalid" />
                    <label for="validBarcode">
                        <img src="Images/green_small.jpg" />&nbsp;&nbsp;Valid</label>
                    &nbsp;&nbsp;&nbsp;<input type="radio" name="validity" id="lunchBarcode1" value="3" class="edit_invalid" />
                    <label for="lunchBarcode">
                        <img src="Images/brown_small.jpg" />&nbsp;&nbsp;Lunch Detention</label>
                    &nbsp;&nbsp;&nbsp;<input type="radio" name="validity" id="saturdayBarcode1" value="4" class="edit_invalid" />
                    <label for="saturdayBarcode">
                        <img src="Images/yellow_small.jpg" />&nbsp;&nbsp;Saturday School</label>
                    <br />
                    <label for="note1">Note 1</label>
                    <textarea name="note1" id="note11" rows="10" cols="5" class="full" placeholder="Optional. Appears with scan results."></textarea>
                    <label for="not2">Note 2</label>
                    <textarea name="note2" id="note21" rows="10" cols="5" class="full" placeholder="Optional. Appears with scan results."></textarea>
                    <label for="note3">Note 3</label>
                    <textarea name="note3" id="note31" rows="10" cols="5" class="full" placeholder="Optional. Appears with scan results."></textarea>
                    <label for="note4">Note 4</label>
                    <textarea name="note4" id="note41" rows="10" cols="5" class="full" placeholder="Optional. Appears with scan results."></textarea>
                    <input type="submit" class="yellow_button ysmall" style="font-size: 1.25em; margin-left: 5%;" value="Save" />
                    <input type="button" class="cancel_edit" style="font-size: 1.25em; margin-left: 5%;" value="Cancel" />
                </form>
            </span>
            <ul class="data" id="datavaluesTable">
                <li id="hidden_placeholder" class="group valuerow">
                    <p class="data_action">
                        <a class="editDatabaseValue a1" href="#">Edit</a>
                        <a class="deleteDatabaseValue" href="#">Delete</a>
                    </p>
                    <form method="post" class="data_form">
                        <input type="hidden" name="action" value="generatebarcode" />
                        <input type="hidden" name="value" />
                        <input type="submit" value="Barcode" class="data_button" />
                    </form>
                    <img src="Images/valid.png" title="Valid" alt="Valid" class="dataicon" />
                    <h1></h1>
                    <h2>
                        <input type="hidden" name="value" />
                        <input type="hidden" name="status" />
                        <input type="hidden" name="response" />

                        <ul id="barcode_response_area">
                            <li></li>
                            <li><a class="editDatabaseValue a2" href="#" id="barcode_response"></a></li>
                        </ul>
                        <input type="hidden" name="fName" />
                        <input type="hidden" name="lName" />
                        <input type="hidden" name="grade" />
                        <input type="hidden" name="note1" />
                        <input type="hidden" name="note2" />
                        <input type="hidden" name="note3" />
                        <input type="hidden" name="note4" />
                    </h2>
                </li>
                <asp:ListView ID="lstScanData" runat="server" ItemPlaceholderID="itemContainer">
                    <LayoutTemplate>
                        <asp:PlaceHolder ID="itemContainer" runat="server"></asp:PlaceHolder>
                    </LayoutTemplate>
                    <ItemTemplate>
                        <li class="group valuerow">
                            <span class="urlencode"><%#Eval("StudentIdNumber").ToString().Replace(" ","+")%></span>
                            <p class="data_action">
                                <a class="editDatabaseValue a1" href="#">Edit</a>
                                <a class="deleteDatabaseValue" href="#">Delete</a>
                            </p>
                            <form method="post" class="data_form">
                                <input type="hidden" name="action" value="generatebarcode" />
                                <input type="hidden" name="value" value="<%#Eval("StudentIdNumber")%>" />
                                <input type="hidden" name="dbid" value="<% =this.GetDatabaseId() %>" />
                                <input type="hidden" name="userid" value="<%=this.GetUserId()%>" />
                                <input type="submit" value="Barcode" class="data_button" />
                            </form>
                            <img src="<%# this.GetValidityImage(Eval("ValidityCode").ToString()) %>" class="dataicon" />
                            <h1><%#Eval("StudentIdNumber")%></h1>
                            <h2 class="valueh2">
                                <input type="hidden" name="value" value="<%#Eval("StudentIdNumber")%>" />
                                <input type="hidden" name="status" value="<%#Eval("ValidityCode")%>" />
                                <input type="hidden" name="fName" value="<%#Eval("FirstName")%>" />
                                <input type="hidden" name="lName" value="<%#Eval("LastName")%>" />
                                <input type="hidden" name="grade" value="<%#Eval("Grade")%>" />
                                <input type="hidden" name="note1" value="<%#Eval("Note1")%>" />
                                <input type="hidden" name="note2" value="<%#Eval("Note2")%>" />
                                <input type="hidden" name="note3" value="<%#Eval("Note3")%>" />
                                <input type="hidden" name="note4" value="<%#Eval("Note4")%>" />
                                <input type="hidden" name="statusImage" value="<%# this.GetValidityImage(Eval("ValidityCode").ToString()) %>" />
                                <ul id="barcode_response_area">
                                    <li></li>
                                    <li><a class="editDatabaseValue a2" href="#" id="A1"><%#Eval("FirstName")%>, <%#Eval("LastName")%></a></li>
                                </ul>
                            </h2>
                        </li>
                    </ItemTemplate>
                    <EmptyDataTemplate>
                        <div>
                        </div>
                    </EmptyDataTemplate>
                </asp:ListView>
            </ul>

            <form runat="server">
                <div class="pagination">
                    <ul id="paginator2">
                        <li id="page_active">
                            <asp:DataPager QueryStringField="pageNumber" OnPreRender="dataPaging_PreRender" ID="DataPager1" runat="server" PagedControlID="lstScanData" PageSize="15">
                                <Fields>
                                    <asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="False" />
                                    <asp:NumericPagerField />
                                    <asp:NextPreviousPagerField ShowLastPageButton="True" ShowPreviousPageButton="False" />
                                </Fields>
                            </asp:DataPager>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <script type="text/javascript">
            $(document).ready(function () {
                var messengerDiv = $("div#showMessages");
                // quick adding values to the database
                $("#addValues").submit(function (event) {

                    var form = $(this);
                    var value = form.find("input:text[name=studentIdNumber]").val();
                    var fname = form.find("input:text[name=firstName]").val();
                    var lname = form.find("input:text[name=lastName]").val();
                    var grade = form.find("input:text[name=grade]").val();
                    var userid = form.find("input:hidden[name=adduserid]").val();
                    var addlistid = form.find("input:hidden[name=listid]").val();
                    if (value == "") return false;
                    var submitbutton = form.find("input:submit");
                    var note1 = form.find("textarea[name=note1]").val();
                    var note2 = form.find("textarea[name=note2]").val();
                    var note3 = form.find("textarea[name=note3]").val();
                    var note4 = form.find("textarea[name=note4]").val();
                    var barcode_status = $("input:radio[name=validity]:checked").val();//$("#validBarcode").is(':checked') ? 0 : 1;
                    var barcode_status_image = '';
                    var barcode_status_title = '';
                    switch (barcode_status) {
                        case "1":
                            barcode_status_image = 'Images/red_small.jpg';
                            barcode_status_title = 'Invalid'
                            break;
                        case "2":
                            barcode_status_image = 'Images/green_small.jpg';
                            barcode_status_title = 'Valid'
                            break;
                        case "3":
                            barcode_status_image = 'Images/brown_small.jpg';
                            barcode_status_title = 'Lunch Detention'
                            break;
                        case "4":
                            barcode_status_image = 'Images/yellow_small.jpg';
                            barcode_status_title = 'Saturday School'
                            break;
                        default:
                            //  alert("under default");
                            // alert(barcode_status);
                            barcode_status_image = 'Images/red_small.jpg';
                            barcode_status_title = 'Invalid'
                            break;
                    }

                    var adddataRq = '<?xml version="1.0" encoding="utf-8"?>' +
				                '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
				                  '<soap:Body>' +
					                '<AddScanData xmlns="http://tempuri.org/">' +
					                  '<dbId>' + addlistid + '</dbId>' +
					                  '<loggedInUserId>' + userid + '</loggedInUserId>' +
					                  '<scanData>' +
                                            '<ScanId>0</ScanId>' +
                                           ' <QuestionId>0</QuestionId> ' +
                                           '<QuestionText/>' +
                                           '<QuestionResponse/> ' +
                                           ' <ServiceId>0</ServiceId> ' +
                                          '<StudentIdNumber>' + value + '</StudentIdNumber>' +
                                          '<FirstName>' + fname + '</FirstName>' +
                                          '<LastName>' + lname + '</LastName>' +
                                          '<Grade>' + grade + '</Grade> ' +
                                          '<ValidityCode>' + barcode_status + '</ValidityCode> ' +
                                          '<Note1>' + note1 + '</Note1>' +
                                          '<Note2>' + note2 + '</Note2> ' +
                                          '<Note3>' + note3 + '</Note3> ' +
                                          '<Note4>' + note4 + '</Note4>   ' +
                                          '<ResponseValue/>' +
                                          '<DeviceId/>  ' +
                                          '<DeviceName/>  ' +
                                          '<ScanStatusMessage/>' +
                                          '<CreateDate/>' +
                                        '<ServiceName/>' +
                                        '<ServiceSubType/>' +
                                        '<UserId>' + userid + '</UserId>' +
                                        '<UserName/>' +
                                      '</scanData>' +
					                '</AddScanData>' +
				                  '</soap:Body>' +
				                '</soap:Envelope>';
                    // alert(adddataRq);
                    $.ajax({
                        type: "POST",
                        url: "http://ssica.org/services/CommonService.asmx?op=AddScanData", // Location of the service
                        data: adddataRq, //Data sent to server
                        contentType: "text/xml;charset-uf8", // content type sent to server
                        dataType: "xml",
                        success: function (xml) {
                            var msg = "";
                            msg = $("AddScanDataResult", xml).text();
                            //   alert(msg);
                            var showMessage;
                            if (msg == 'success') {
                                form.find("input:text").val("");
                                form.find("textarea").val("");
                                $("#invalidBarcode").attr("checked", true);
                                var newTableRow0 = $("#hidden_placeholder").clone().insertAfter($("#hidden_placeholder")).show().removeAttr('id');
                                var newTableRow = newTableRow0;

                                newTableRow.find("h2 > input:hidden[name=value]").val(value);
                                newTableRow.find("h2 > input:hidden[name=fName]").val(fname);
                                newTableRow.find("h2 > input:hidden[name=lName]").val(lname);
                                newTableRow.find("h2 > input:hidden[name=grade]").val(grade);
                                newTableRow.find("h2 > input:hidden[name=note1]").val(note1);
                                newTableRow.find("h2 > input:hidden[name=note2]").val(note2);
                                newTableRow.find("h2 > input:hidden[name=note3]").val(note3);
                                newTableRow.find("h2 > input:hidden[name=note4]").val(note4);
                                //  alert(newTableRow.find("h2 > input:hidden[name=note4]").val());
                                newTableRow.find("img.dataicon").attr({
                                    alt: barcode_status_title,
                                    title: barcode_status_title,
                                    src: barcode_status_image
                                }).
                                next().html($('<span>').text(value).html());
                                barcode_response = fname + "," + lname;
                                barcode_response.replace(/\n/g, "<br/>");

                                newTableRow.find("h2 > input:hidden[name=value]").val(value).
                                next().val(barcode_status).
                                next().val(barcode_response).
                                next().find("li:eq(1) > a").empty().append(barcode_response ? $('<span>').text(barcode_response).html() : 'Add Student Detail');

                                if ($("#emptyDatabasePlaceholder").length) {
                                    $("#emptyDatabasePlaceholder").remove();
                                }

                                showMessage = 'Student Detail has been added.';
                                messengerDiv.removeClass().addClass("success");
                            } else {
                                if (msg == 'nosuccess') {
                                    showMessage = 'Student Detail  already exists thus cannot be added.';
                                } else if (msg == 'empty') {
                                    showMessage = 'Student# cannot be empty.';
                                }
                                messengerDiv.removeClass().addClass("warning");
                            }
                            if (messengerDiv.is(":empty")) {
                                messengerDiv.empty().append("<p></p>").append("<li>" + showMessage + "</li>").hide().slideDown();
                            } else {
                                messengerDiv.hide().empty().append("<p></p>").append("<li>" + showMessage + "</li>").fadeIn();
                            }
                            $("#LoadingDiv").hide();
                            submitbutton.fadeIn("fast");

                        }
                    });
                    form.find("input:text[name=value]").focus();
                    return false;
                });

                $("a.editDatabaseValue").live("click", function (event) {
                    if ($(this).hasClass('a1')) {
                        var td = $(this).parent().parent().find('h2');
                    } else if (1 || $(this).hasClass('a2')) {
                        var td = $(this).parent().parent().parentsUntil('li.valuerow');
                    }

                    td.data('BeforeEditing', td.html());
                    var barcode_value = td.find("input:hidden[name='value']").val();
                    var barcode_status = td.find("input:hidden[name='status']").val();
                    var fName = td.find("input:hidden[name='fName']").val();
                    var lName = td.find("input:hidden[name='lName']").val();
                    var _grade = td.find("input:hidden[name='grade']").val();
                    var _note1 = td.find("input:hidden[name='note1']").val();
                    var _note2 = td.find("input:hidden[name='note2']").val();
                    var _note3 = td.find("input:hidden[name='note3']").val();
                    var _note4 = td.find("input:hidden[name='note4']").val();
                    //alert(_note1);
                    td.empty().html($("#editBarcodeFormHidden").html());

                    td.find("input#input_invalid").attr('id', 'input_invalid_temp');
                    td.find("label#label_for_input_invalid").attr('for', 'input_invalid_temp');

                    td.find("input:hidden[name='value']").val(barcode_value);
                    if (barcode_status == 1) {
                        td.find("#invalidBarcode1").attr('checked', 'checked');
                    } else if (barcode_status == 2) {
                        td.find("#validBarcode1").attr('checked', 'checked');
                    } else if (barcode_status == 3)
                    { td.find("#lunchBarcode1").attr('checked', 'checked'); }
                    else if (barcode_status == 4) {
                        td.find("#saturdayBarcode1").attr('checked', 'checked');
                    }
                    td.find("input:text[name='sid']").val(barcode_value);
                    td.find("input:text[name='fName']").val(fName);
                    td.find("input:text[name='lName']").val(lName);
                    td.find("input:text[name='grade']").val(_grade);
                    td.find("textarea[name='note1']").val(_note1);
                    td.find("textarea[name='note2']").val(_note2);
                    td.find("textarea[name='note3']").val(_note3);
                    td.find("textarea[name='note4']").val(_note4);
                    return false;
                });

                $("input.cancel_edit").live("click", function (event) {
                    var td = $(this).parent().parent();
                    td.empty().html(td.data('BeforeEditing'));
                    return false;
                });

                $("form.editBarcodeForm").live("submit", function (event) {
                    var td = $(this).parent();
                    var dbid = td.find("input:hidden[name='dbid']").val();
                    var userid = td.find("input:hidden[name='userid']").val();
                    var barcode_value = td.find("input:hidden[name='value']").val();
                    //  var barcode_status = td.find("input:text[name='fName']").val();
                    barcode_response = $.trim(barcode_response);
                    var new_barcode = td.find("input:text[name='sid']").val();
                    var f_Name = td.find("input:text[name='fName']").val();
                    var l_Name = td.find("input:text[name='lName']").val();
                    var validity = td.find("input[name='validity']:checked").val();
                    var grade = td.find("input:text[name='grade']").val();
                    var note1 = td.find("textarea[name='note1']").val();
                    var note2 = td.find("textarea[name='note2']").val();
                    var note3 = td.find("textarea[name='note3']").val();
                    var note4 = td.find("textarea[name='note4']").val();
                    var barcode_response = f_Name + "," + l_Name;
                    var barcode_status_image = GetStatusImageURL(validity); //td.find("input:hidden[name='statusImage']").val();
                    //  alert(barcode_status_image);
                    var barcode_status_title = barcode_status_image;
                    var _data = '<?xml version="1.0" encoding="utf-8"?>' +
                                '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
                                  '<soap:Body>' +
                                    '<EditScanData xmlns="http://tempuri.org/">' +
                                      '<dbId>' + dbid + '</dbId>' +
                                      '<loggedInUserId>' + userid + '</loggedInUserId>' +
                                      '<firstName>' + f_Name + '</firstName>' +
                                      '<lastName>' + l_Name + '</lastName>' +
                                      '<StudentIdNumber>' + new_barcode + '</StudentIdNumber>' +
                                      '<oldStudentId>' + barcode_value + '</oldStudentId>' +
                                     '<grade>' + grade + '</grade>' +
                                      '<validity>' + validity + '</validity>' +
                                      '<note1>' + note1 + '</note1>' +
                                      '<note2>' + note2 + '</note2>' +
                                      '<note3>' + note3 + '</note3>' +
                                      '<note4>' + note4 + '</note4>' +
                                    '</EditScanData>' +
                                  '</soap:Body>' +
                                '</soap:Envelope>';
                    //alert(_data);
                    $.ajax({
                        type: "POST",
                        url: "http://services.ssica.org/services/CommonService.asmx?op=EditScanData", // Location of the service
                        data: _data, //Data sent to server
                        contentType: "text/xml;charset-uf8", // content type sent to server
                        dataType: "xml",
                        success: function (xml) {
                            var msg = "";
                            msg = $("EditScanDataResult", xml).text();
                            //     alert(msg);
                            if (msg == 'success') {
                                td.empty().html(td.data('BeforeEditing'));
                                td.find("input:hidden[name=value]").val(new_barcode).
                                next().val(validity).
                                next().val(f_Name).
                                next().val(l_Name).
                                next().val(grade).
                                next().val(note1).
                                next().val(note2).
                                next().val(note3).
                                next().val(note4);
                                td.parent().find('h1').text(new_barcode);
                                td.parent().find('img:first').attr({
                                    alt: barcode_status_title,
                                    title: barcode_status_title,
                                    src: barcode_status_image
                                });
                                td.find('a').empty().append(barcode_response ? $('<span>').text(barcode_response.replace(/\n/g, "<br/>")) : 'Add a Student Name');
                            }
                            var showMessage;
                            if (msg == 'success') {
                                showMessage = 'Student Details has been updated.';
                                messengerDiv.removeClass().addClass("success");
                            } else if (msg == 'nosuccess') {
                                showMessage = 'Error while updating student detail.';
                                messengerDiv.removeClass().addClass("warning");
                            } else {
                                showMessage = msg;
                                messengerDiv.removeClass().addClass("warning");
                            }


                            if (messengerDiv.is(":empty")) {
                                messengerDiv.empty().append("<p></p>").append("<li>" + showMessage + "</li>").hide().slideDown();
                            } else {
                                messengerDiv.hide().empty().append("<p></p>").append("<li>" + showMessage + "</li>").fadeIn();
                            }
                        }
                    });
                    return false;
                });

                $("a.deleteDatabaseValue").live("click", function (event) {
                    var tr = $(this).parent().parent();
                    var value = $(this).parent().parent().find("form > input:hidden[name=value]").val();
                    var dbId = $(this).parent().parent().find("form > input:hidden[name=dbid]").val();
                    var userId = $(this).parent().parent().find("form > input:hidden[name=userid]").val();
                    var loading_icon = '<img src="Images/loading-white.gif"/>';
                    $(this).parent().html(loading_icon);

                    var _deleRq = '<?xml version="1.0" encoding="utf-8"?>' +
                                    '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
                                      '<soap:Body>' +
                                        '<DeleteScanData xmlns="http://tempuri.org/">' +
                                          '<dbId>' + dbId + '</dbId>' +
                                          '<loggedInUserId>' + userId + '</loggedInUserId>' +
                                          '<studentIdNumber>' + value + '</studentIdNumber>' +
                                          '<hashCode>testvalue</hashCode>' +
                                        '</DeleteScanData>' +
                                      '</soap:Body>' +
                                    '</soap:Envelope>';
                    $.ajax({
                        type: "POST",
                        url: "http://ssica.org/services/CommonService.asmx?op=DeleteScanData", // Location of the service
                        data: _deleRq, //Data sent to server
                        contentType: "text/xml;charset-uf8", // content type sent to server
                        dataType: "xml",
                        success: function (xml) {
                            var msg = "";
                            msg = $("DeleteScanDataResult", xml).text();
                            tr.fadeOut().remove();
                            messengerDiv.removeClass().addClass("success");
                            var showMessage = 'Barcode value has been deleted.';
                            if (messengerDiv.is(":empty")) {
                                messengerDiv.empty().append("<p></p>").append("<li>" + showMessage + "</li>").hide().slideDown();
                            } else {
                                messengerDiv.hide().empty().append("<p></p>").append("<li>" + showMessage + "</li>").fadeIn();
                            }
                        }
                    });
                    return false;
                });
            });

            function GetStatusImageURL(statusCode) {
                var imageUrl = "";
                switch (statusCode) {
                    case "1":
                        imageUrl = "Images/red.jpg";
                        break;
                    case "2":
                        imageUrl = "Images/green.jpg";
                        break;
                    case "3":
                        imageUrl = "Images/brown.jpg";
                        break;
                    case "4":
                        imageUrl = "Images/yellow.jpg";
                        break;
                    case "5":
                        imageUrl = "Images/blue.jpg";
                        break;
                    default:
                        imageUrl = "Images/red.jpg";
                        break;
                }
                return imageUrl;
            }
        </script>
    </div>
</asp:Content>
